//app.js
App({

  globalData: {
    userInfo: null
  },

  getUserInfo: function (cb) {
    var that = this
    if (this.globalData.userInfo) {
      typeof cb == "function" && cb(this.globalData.userInfo)
    } else {
      //调用登录接口
      wx.getUserInfo({
        withCredentials: false,
        success: function (res) {
          that.globalData.userInfo = res.userInfo
          typeof cb == "function" && cb(that.globalData.userInfo)
        }
      })
    }
  },

  //app启动执行
  onLaunch: function () {
    //调用API从本地缓存中获取数据
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    getUserInfo();
  },

  //从后台进前台执行
  onShow: function () {
    console.log("从后台进前台");
  },

  //从前台进后台
  onHide: function () {
    console.log("从前台进后台");
  }
})
